package models

import (
	"github.com/astaxie/beego/orm"
	_ "github.com/go-sql-driver/mysql" // import your used driver

)

type User struct {
	Id   int    `orm:"pk;auto;unique;column(id)" json:"id"`
	Name string `orm:"column(name);size(128)" json:"name"`          // name
	Age  int    `orm:"column(age);type(int);default(0)" json:"age"` //age
}

func init() {
	// set default database
	orm.RegisterDataBase("default", "mysql", "root:123456@tcp(127.0.0.1:3306)/test?charset=utf8", 30)

	// register model
	orm.RegisterModel(new(User))
}


//查询
func GetById(id int) (*User, error) {
	r := new(User)
	err := orm.NewOrm().QueryTable("user").Filter("id", id).One(r)
	if err != nil {
		return nil, err
	}
	return r, nil
}